# C: 令狐冰璃，UTF-8，V0.1  2024.10.04
# Copyright belongs to 令狐冰璃 Encodin=UTF-8 V3.0  2024.10.04
# 代码修改审核后署名

import tkinter as tk
import tkinter.messagebox as messagebox
import random
import time
import webbrowser
import ctypes
import pyautogui
import string
from pynput import keyboard
import threading
import monitor
import os

# 随机标题
biaoti = random.randint(1, 7)

tit = {
    1: "欢迎使用令狐冰璃的刷屏小工具",
    2: "冰璃NN刷屏工具~~",
    3: "现在是2.0！！！好耶！",
    4: "你或许发现了，这是个彩蛋！！！",
    5: "现在开始，你真的能看下去吗？",
    6: "早上好，中午好，晚上好！！！",
    7: "璃璃问你玩PUBG吗？？",
}

root = tk.Tk()
root.title(tit[biaoti])
root.geometry("680x460")

# 生成随机字符串
def generate_random_string(length=3):
    letters = string.ascii_lowercase  # 包含26个小写字母
    return ''.join(random.choice(letters) for _ in range(length))

# 刷屏功能
def spam_channel(stop_event, duration_seconds, interval_seconds, string_length=3):
    start_time = time.time()

    def on_press(key):
        if key == keyboard.Key.space:  # 检测到空格键
            stop_event.set()  # 设置停止事件
            listener.stop()  # 停止监听

    listener = keyboard.Listener(on_press=on_press)  # 创建键盘监听器
    listener.start()  # 开始监听

    while time.time() - start_time < duration_seconds and not stop_event.is_set():
        try:
            random_string = generate_random_string(string_length)
            pyautogui.write(random_string)
            pyautogui.press('enter')
            pyautogui.press('enter')
            time.sleep(interval_seconds)
        except Exception as e:
            print(f"刷屏过程中发生错误: {e}")
            break


# 查询功能
def Inquires():
    tk.Label(root, text="已打开nn官网").place(x=260, y=310)
    webbrowser.open('https://web.nn.com/playCenter')

# 监控功能
monitor_stop_event = threading.Event()

def off_monitor():
    monitor_stop_event.set()  # 设置停止事件
    tk.Label(root, text="自动监控入场欢迎已关闭").place(x=260, y=370)
    button = tk.Button(root, text="打开监控入场欢迎", command=on_monitor)
    button.place(x=20, y=370)

def on_monitor():
    global monitor_stop_event
    custom_message = custom_message_var.get()
    if not custom_message:
        messagebox.showinfo("提示", "使用默认欢迎字符: '欢迎来到Tr'")
    tk.Label(root, text="自动监控入场欢迎已开启").place(x=260, y=370)
    button = tk.Button(root, text="关闭监控入场欢迎", command=off_monitor)
    button.place(x=20, y=370)
    print("自定义字符:", custom_message)
    monitor_stop_event.clear()  # 清除停止事件

    def monitor_loop():
        while not monitor_stop_event.is_set():
            try:
                monitor.screenshot_and_process(custom_message)
                time.sleep(6)
            except Exception as e:
                print(f"监控过程中发生错误: {e}")
                break

    monitor_thread = threading.Thread(target=monitor_loop, daemon=True)
    monitor_thread.start()

# 提示消息
def message1():
    user32 = ctypes.WinDLL('user32', use_last_error=True)
    MB_ICONERROR = 0x00000010
    MB_OK = 0x00000000
    user32.MessageBoxW(None, '杂鱼，叫你不要点我了！QAQ', '坏蛋！', MB_ICONERROR | MB_OK)

def message2():
    user32 = ctypes.WinDLL('user32', use_last_error=True)
    MB_ICONERROR = 0x00000010
    MB_OK = 0x00000000
    user32.MessageBoxW(None, '杂鱼杂鱼，小杂鱼，小心床底有狐狸冒出来！', '笨蛋！！！', MB_ICONERROR | MB_OK)

# 随机提示
tishi = random.randint(1, 2)

if tishi == 1:
    def caidan():
        message1()
else:
    def caidan():
        message2()

# 变量定义
duration_var = tk.StringVar(value="120")
interval_var = tk.StringVar(value="0.05")
length_var = tk.StringVar(value="3")
custom_message_var = tk.StringVar()  # 自定义字符输入框

# 输入框和标签
tk.Label(root, text="刷屏持续时间 (秒):").grid(row=0, column=0, padx=10, pady=10, sticky='e')
tk.Entry(root, textvariable=duration_var, width=10).grid(row=0, column=1, padx=10, pady=10)

tk.Label(root, text="刷屏间隔 (秒):").grid(row=1, column=0, padx=10, pady=10, sticky='e')
tk.Entry(root, textvariable=interval_var, width=10).grid(row=1, column=1, padx=10, pady=10)

tk.Label(root, text="刷屏长度 (字符):").grid(row=2, column=0, padx=10, pady=10, sticky='e')
tk.Entry(root, textvariable=length_var, width=10).grid(row=2, column=1, padx=10, pady=10)

tk.Label(root, text="自定义字符:").grid(row=3, column=0, padx=10, pady=10, sticky='e')
tk.Entry(root, textvariable=custom_message_var, width=20).grid(row=3, column=1, padx=10, pady=10)

# 按钮
tk.Label(root, text="点击后5秒开始刷屏，请点击输入框，按下空格停止").grid(row=4, column=0, columnspan=2, padx=10, pady=10, sticky='w')
button = tk.Button(root, text="开始刷屏", command=lambda: on_button_click())
button.grid(row=5, column=0, columnspan=2, pady=20, padx=100)

tk.Label(root, text="点击查询NN所有大厅热度").grid(row=6, column=0, columnspan=2, padx=10, pady=10, sticky='w')
button = tk.Button(root, text="查询", command=Inquires)
button.grid(row=6, column=1, pady=20, padx=10)

# 监控功能按钮
button = tk.Button(root, text="打开监控入场欢迎", command=on_monitor)
button.place(x=20, y=370)

# 彩蛋按钮
button = tk.Button(root, text="不要戳哦~~", command=caidan)
button.place(x=20, y=420)

# 按钮点击事件
def on_button_click():
    duration = float(duration_var.get())
    interval = float(interval_var.get())
    string_length = int(length_var.get())
    stop_event = threading.Event()
    root.after(5000, lambda: threading.Thread(target=spam_channel, args=(stop_event, duration, interval, string_length), daemon=True).start())

root.mainloop()
